/**
 * @file implements ImageLoader
 * @author CORSAR <vladimir.corsair@gmail.com>
 * @version 2.0.0
 */

/**
 * Image Loader, loads the images
 * @param {type} resourcesList manifest.images
 * @returns {ImageLoader}
 */
var ImageLoader = function (resourcesList) {
    this.resources = resourcesList;
    this.loadedImages = [];
};

/**
 * Load image resource
 * @param {String} id path to the image file
 * @param {type} callb callback function when image is loaded
 * @returns {Image}
 */
ImageLoader.prototype.load = function (id, callb) {
    if(this.loadedImages[id]) {
        if(callb) callb.call(this);
        return this.loadedImages[id];
    }
    var image = new Image();
    image.src = this.resources[id] || null;
    image.onload = callb ? callb.bind(this) : null;
    this.loadedImages[id] = image;
    return image;
};